/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package AddProductManager;

import java.sql.*;
import DBManager.DBConnection;

/**
 *
 * @author Alex
 */
public class AddProductManager {
    
    public boolean addProduct(Product newProduct)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
            PreparedStatement pstmt =
                conn.prepareStatement("INSERT "
                    + "INTO products(mangid,title,synopsis,price,type)"
                    + " values(?,?,?,?,?)");

            //append values for the parameters
            int i=1;
             pstmt.setInt(i++, newProduct.getMangid());
        pstmt.setString(i++, newProduct.getTitle());
        pstmt.setString(i++, newProduct.getSypnosis());
        pstmt.setInt(i++, Integer.parseInt(newProduct.getPrice()));
        pstmt.setString(i++, newProduct.getType());
           
            //execute SQL statement
            pstmt.executeUpdate();

            result = true;
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
}
